﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Jzy.BLL.SiteAdmin;
using Jzy.Model.SiteAdmin;
using Jzy.Core.Common.Web;

namespace ECommerce.Web.SiteAdmin.Profile
{
    public partial class Edit : PageEdit
    {
        private CompanyBO _company;

        private CompanyBO Company
        {
            get
            {
                if (_company == null)
                {
                    _company = new CompanyBO();
                }
                return _company;
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                DispInfo();
            }
        }

        private void DispInfo()
        {
            string url = GetDomain();
            //CompanyInfo info = Company.GetInfoByUrl(url);
            List<CompanyInfo> list = Company.GetList();
            CompanyInfo info;
            if (list.Count == 0)
            {
                info = this.Company.InitInfo(url);
            }
            else
            {
                info = list.First();
            }

            EntityUtil.SetControl(pnlMain, info);



        }

        protected void btnSave_Click(object sender, EventArgs e)
        {
            string url = GetDomain();
            CompanyInfo info = Company.GetList().First();
            EntityUtil.SetEntity(pnlMain, info);


            this.Company.Save(info);


            Jzy.Core.Utility.JSUtil.Alert("保存成功");
        }
    }
}